<template>
  <div class="accessory">
    <el-form :model="CloudAttachmentSet" label-width="207px" ref="dataForm">
      <el-form-item label="附件功能">
        <el-radio-group v-model="CloudAttachmentSet.status">
          <el-radio label="1">开启</el-radio>
          <el-radio label="0">关闭</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="业务设置">
        <el-checkbox-group v-model="CloudAttachmentSet.businessSetArr">
          <el-checkbox v-for="business in businessList" :label="business.id" :key="business.id">{{ business.name }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="附件大小">
        <el-input v-model="CloudAttachmentSet.attachmentSize" style="width:150px;"/>&nbsp;MB
        <p style="margin:0;color:#7a7a7a;margin-left:40px;">当前服务器附件大小上限为2048MB</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="margin-left:40px;" @click="createData()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

  import {addData, getData} from '@/api/cloud/cloud_attachment_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        CloudAttachmentSet: {
          status: '1',
          businessSetArr: [],
          attachmentSize: '500'
        },
        businessList: [{id: "1", name: "资讯"}, {id: "2", name: "课程讨论区"}, {id: "3", name: "班级话题"}, {id: "4", name: "小组"}, {id: "5", name: "试题"}]
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getData(getTenantId()).then(response => {
          if (response.data) {
            this.CloudAttachmentSet = response.data
          }
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.CloudAttachmentSet.tenantId = getTenantId();
            addData(this.CloudAttachmentSet).then(() => {
              this.$notify({
                title: '成功',
                message: '操作成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .accessory {
    padding-top: 30px;

    .el-form {
      .el-form-item__label {
        margin-right: 40px;
        font-size: 16px;
      }
    }
  }
</style>
